package operation;

import java.sql.SQLOutput;
import java.util.Random;

public class strCut extends Operation implements Ioperation{
    public void work(String str){
        char[] arr = str.toCharArray();
        Random random = new Random();
        int num = random.nextInt(arr.length);
        System.out.println("随机切割位置是" + num);
        char[] arr2 = new char[arr.length];
        System.out.println("切割后字符串是:");
        for (int i = 0; i < num; i++) {
            arr2[i] = arr[i];
            System.out.print(arr2[i]);
        }
        System.out.println();
    }

    public void work(String str, int num){
        char[] arr = str.toCharArray();
        char[] arr2 = new char[arr.length];
        if(num > str.length() || num < 0){
            System.out.println("非法下标");
            return;
        }
        System.out.println("切割后字符串是:");
        for (int i = 0; i < num; i++) {
            arr2[i] = arr[i];
            System.out.print(arr2[i]);
        }
        System.out.println();

    }
}
